Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@nuxtjs/proxy
Advanced tools
@nuxtjs/proxy is a Nuxt.js module that allows you to easily configure proxy middleware for your Nuxt.js application. This is particularly useful for handling API requests during development, avoiding CORS issues, and routing requests to different backends.
Basic Proxy Setup
This feature allows you to set up a basic proxy configuration. In this example, any request to `/api/` will be proxied to `http://api.example.com`, and the `/api/` prefix will be removed from the request path.
json
{
"modules": [
"@nuxtjs/proxy"
],
"proxy": {
"/api/": {
"target": "http://api.example.com",
"pathRewrite": { "^/api/": "" }
}
}
}
Multiple Proxies
This feature allows you to set up multiple proxy configurations. In this example, requests to `/api/` are proxied to `http://api.example.com`, and requests to `/auth/` are proxied to `http://auth.example.com`.
json
{
"modules": [
"@nuxtjs/proxy"
],
"proxy": {
"/api/": {
"target": "http://api.example.com",
"pathRewrite": { "^/api/": "" }
},
"/auth/": {
"target": "http://auth.example.com",
"pathRewrite": { "^/auth/": "" }
}
}
}
Custom Proxy Options
This feature allows you to customize proxy options. In this example, `changeOrigin` is set to `true` to change the origin of the host header to the target URL, and `secure` is set to `false` to allow self-signed SSL certificates.
json
{
"modules": [
"@nuxtjs/proxy"
],
"proxy": {
"/api/": {
"target": "http://api.example.com",
"pathRewrite": { "^/api/": "" },
"changeOrigin": true,
"secure": false
}
}
}
http-proxy-middleware is a popular Node.js package for creating proxy middleware. It offers a wide range of customization options and can be used with various frameworks like Express, Koa, and more. Compared to @nuxtjs/proxy, it requires more manual setup but offers greater flexibility.
axios is a promise-based HTTP client for the browser and Node.js. While it is not a proxy middleware, it can be used in conjunction with proxy settings to handle API requests. It is more focused on making HTTP requests rather than setting up proxies, but it can be configured to work with proxy servers.
node-http-proxy is a full-featured HTTP proxy for Node.js. It provides a robust set of features for creating proxy servers and routing HTTP requests. It is more low-level compared to @nuxtjs/proxy and requires more configuration, but it offers extensive customization options.
Proxy support for nuxt server
✓ Path rewrites
✓ Host based router (useful for staging/test)
✓ Logs / Proxy Events
✓ WebSockets
✓ Auth / Cookie
✓ ...See http-proxy-middleware docs
⚠ Does not work in generated/static mode!
@nuxtjs/proxy
dependency to your projectyarn add @nuxtjs/proxy # or npm install @nuxtjs/proxy
@nuxtjs/proxy
to the modules
section of nuxt.config.js
{
modules: [
// Simple usage
'@nuxtjs/proxy',
// With options
['@nuxtjs/proxy', { pathRewrite: { '^/api' : '/api/v1' } }]
]
}
proxy
section of nuxt.config.js
(See proxy section below)changeOrigin
and ws
options are enabled by default.[optional] You can provide default options to all proxy targets by passing options to module options.
proxy
You can provide proxy config using either object or array.
You can use shorthand syntax to configure proxy:
{
proxy: [
// Proxies /foo to http://example.com/foo
'http://example.com/foo',
// Proxies /api/books/*/**.json to http://example.com:8000
'http://example.com:8000/api/books/*/**.json',
// You can also pass more options
[ 'http://example.com/foo', { ws: false } ]
]
}
Keys are context
{
proxy: {
// Simple proxy
'/api': 'http://example.com',
// With options
'/api2': { target: 'http://example.com', ws: false },
// Proxy to backend unix socket
'/api3': {
changeOrigin: false,
target: { socketPath: '/var/run/http-sockets/backend.sock' }
}
}
}
yarn install
or npm install
npm run dev
Copyright (c) Nuxt Community
FAQs
proxy support for nuxt server
The npm package @nuxtjs/proxy receives a total of 102,638 weekly downloads. As such, @nuxtjs/proxy popularity was classified as popular.
We found that @nuxtjs/proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.